import {request} from '../utils/request'

const questionBankApi = {
  findAllSubjects: '/subject/findAllSubjects',
  findSubjectsByHouse: '/subject/findSubjectsByHouse',
  postNewBank: '/questionBank/add',
  findBank: '/questionBank/liberary/search',
  applyCheckBank: '/questionBank/apply',
  findSubjectById: '/subject/findSubjectByID',
  deleteQuestions: '/questionBank/deleteQuestions'
}

// 查询所有科目
export function findAllSubjects (parameter) {
  return request({
    url: questionBankApi.findAllSubjects,
    method: 'get',
    params: parameter
  })
}

// 根据学院查询科目
export function findSubjectsByHouse (house) {
  return request({
    url: questionBankApi.findSubjectsByHouse,
    method: 'get',
    params: {
      house: house
    }
  })
}

// 根据科目查询题库
export function findBankBySubject (index, pageSize, sid) {
  return request({
    url: questionBankApi.findBank,
    method: 'get',
    params: {
      index: index,
      page_size: pageSize,
      subjectId: sid
    }
  })
}

// 根据题库名查找题库
export function findBankByName (index, pageSize, name, teacherId) {
  return request({
    url: questionBankApi.findBank,
    method: 'get',
    params: {
      index: index,
      page_size: pageSize,
      name: name,
      teacherId: teacherId
    }
  })
}

// 添加新题库
export function postNewBank (newBank) {
  return request({
    url: questionBankApi.postNewBank,
    method: 'post',
    data: {
      name: newBank.name,
      subjectId: newBank.subjectId,
      teacherId: newBank.teacherId
    }
  })
}

// 根据所属老师查询题库
export function findBankByTeacher (parameters) {
  return request({
    url: questionBankApi.findBank,
    method: 'get',
    params: {
      index: parameters.index,
      page_size: parameters.page_size,
      teacherId: parameters.teacherId
    }
  })
}

// 根据所属老师，状态、科目查询题库
export function findBankSearch (parameters) {
  return request({
    url: questionBankApi.findBank,
    method: 'get',
    params: {
      index: parameters.index,
      page_size: parameters.page_size,
      teacherId: parameters.teacherId,
      subjectId: parameters.subjectId,
      status: parameters.status
    }
  })
}

// 申请审核题库
export function applyCheckBank (bankId) {
  return request({
    url: questionBankApi.applyCheckBank,
    method: 'post',
    params: {
      bankId: bankId
    }
  })
}

export function deleteQuestions (info) {
  return request({
    url: questionBankApi.deleteQuestions,
    method: 'post',
    params: {
      bankId: info.bankId
    },
    data: info.listOfId
  })
}

// 通过id查找科目
export function findSubjectById (id) {
  return request({
    url: questionBankApi.findSubjectById,
    method: 'get',
    params: {
      id: id
    }
  })
}
